<?php

$servername = "localhost";
$username = "root";
$password = "root";
try {
  $conn = new PDO("mysql:host=$servername;dbname=dish;", $username, $password);
  echo "连接成功<br/>";
} catch (PDOException $e) {
  echo $e->getMessage();
}
$conn->exec("set names utf8;");
$sql = "select * from dish;";
$psql = $conn->prepare($sql);
$o = $psql->execute();
$all = $psql->fetchAll();
$size = sizeof($all);

?>


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>

  <?php

  for ($i = 0; $i < $size; $i = $i + 1) {
    $item = $all[$i];
    ?>

    <div>
      菜品：
      <?php echo $item['dish_name']; ?>
      价格：
      <?php echo $item['price']; ?>
      <img src="<?php echo $item['dish_name'] .'.'. $item['img_ext_name']; ?>" />
    </div>
 红烧肉.jpg
  <?php } ?>

</body>

</html>